package com.kaikai.eduorder.service.impl;


import com.kaikai.eduorder.client.CourseClient;
import com.kaikai.eduorder.client.UcenterClient;
import com.kaikai.eduorder.entity.Order;
import com.kaikai.eduorder.mapper.OrderMapper;
import com.kaikai.eduorder.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import vo.CommentUserInfo;
import vo.EduCourseOrder;

import java.util.UUID;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author yujiankai
 * @since 2021-06-18
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Autowired
    private CourseClient courseClient;
    @Autowired
    private UcenterClient ucenterClient;
    @Override
    public String createOrder(String courseId, String memberId) {
        //获得课程信息
        EduCourseOrder eduCourseOrder = courseClient.getDto(courseId);
        //获得用户信息

        CommentUserInfo userInfo = ucenterClient.getUserInfo(memberId);
        Order order=new Order();

        order.setOrderNo(UUID.randomUUID().toString());
        order.setCourseId(courseId);
        order.setCourseTitle(eduCourseOrder.getTitle());
        order.setCourseCover(eduCourseOrder.getCover());
        order.setTeacherName(eduCourseOrder.getTeacherName());
        order.setTotalFee(eduCourseOrder.getPrice());
        order.setMemberId(memberId);
        order.setMobile(userInfo.getMobile());
        order.setNickname(userInfo.getNickname());
        order.setTeacherName("test");
        order.setStatus(0);
        order.setPayType(1);
        baseMapper.insert(order);
        return order.getOrderNo();
    }
}
